import React, { Component } from "react";
import {
  BrowserRouter as Router,
  Route,
  Switch,
  Redirect,
} from "react-router-dom";
import Layout from "./Pages/Layout";
import Login from "./Pages/Login";

export default class App extends Component {
  render() {
    return (
      <Router>
        <Switch>
          <Route path="/login" component={Login}></Route>
          <Route
            path="/"
            render={(props) => {
              const token = localStorage.getItem("geek-pc");
              if (token) {
                return <Layout {...props} />;
              } else {
                return (
                  <Redirect
                    to={{ pathname: "/login", state: { form: props.location } }}
                  />
                );
              }
            }}
          />
        </Switch>
      </Router>
    );
  }
}
